﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OracleClient;
namespace BenefitHelper.Data.ServerData
{
    /// <summary>
    /// 平台上面的客户
    /// </summary>
    public class T_Custome
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 客户姓名
        /// </summary>
        public string CustomeName { get; set; }
        /// <summary>
        /// 证件号码
        /// </summary>
        public string IDCard { get; set; }
        /// <summary>
        /// 手机号
        /// </summary>
        public string Mobile { get; set; }
        /// <summary>
        /// 座机
        /// </summary>
        public string Telphone { get; set; }
        /// <summary>
        /// 电邮
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 联系地址
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// 邮编
        /// </summary>
        public string Zipcode { get; set; }
        /// <summary>
        /// 开户者类型
        /// </summary>
        public string Type { get; set; }
        /// <summary>
        /// 银行编号
        /// </summary>
        public int BankId { get; set; }
        /// <summary>
        /// 银行账户
        /// </summary>
        public string BankAccount { get; set; }
        /// <summary>
        /// 照片
        /// </summary>
        public string Photo { get; set; }
        /// <summary>
        /// 证件类型
        /// </summary>
        public string Credentials_Type { get; set; }

        public List<T_Custome> GetList()
        {
            List<T_Custome> customes = new List<T_Custome>();
            string sql = "select * from T_Custome";
            OracleDataReader sdr = Common.ADO.Tools.OracleHelper.ExecuteReader(sql);
            while (sdr.Read())
            {
                T_Custome c = new T_Custome();
                c.Address = sdr["Address"].ToString();
                c.BankAccount = sdr["BankAccount"].ToString();
                c.BankId = Convert.ToInt32(sdr["BankId"]);
                c.Credentials_Type = sdr["Credentials_Type"].ToString();
                c.Id = Convert.ToInt32(sdr["Id"]);
                c.CustomeName = sdr["CustomeName"].ToString();
                c.Email = sdr["Email"].ToString();
                c.IDCard = sdr["IDCard"].ToString();
                c.Mobile = sdr["Mobile"].ToString();
                c.Photo = sdr["Photo"].ToString();
                c.Telphone = sdr["Telphone"].ToString();
                c.Type = sdr["Type"].ToString();
                c.Zipcode = sdr["Zipcode"].ToString();
                customes.Add(c);
            }
            sdr.Close();
            return customes;
        }

        public List<T_Custome> GetUnRegistCustomes(DB.DBManager db)
        {
            List<Data.ServerData.T_Custome> customes = this.GetList();
            List<Data.ServerData.T_Custome> unRegistCustomes = new List<Data.ServerData.T_Custome>();
            var query = from t in db.Operators select t;
            List<Sys.Operator> operators = query.ToList();
            foreach (T_Custome c in customes)
            {
                bool isExist = false;
                var query2 = from t in operators where c.CustomeName.Equals(t.UName) select t;
                if (query2.Count() > 0)
                {
                    isExist = true;
                }
                if (!isExist)
                {
                    unRegistCustomes.Add(c);
                }
            }
            return unRegistCustomes;
        }
    }
}